from django.shortcuts import render
from django.views import View
from meiduo_mall.libs.captcha.captcha import captcha
from django import http
import random
from meiduo_mall.utils.response_code import RETCODE

class ImageCodeView(View):

    def get(self, request, uuid):
        # 1.生成图片数据
        text, code, image = captcha.generate_captcha()

        # 2.保存图片文本, 用于后续对比

        # 3.输出图片数据
        return http.HttpResponse(image, content_type='image/png')



class SmsCodeView(View):

    def get(self, request, mobile):
        """短信验证码"""
        # 1.随机生成6位数
        sms_code = '%06d' % random.randint(0, 999999)
        # 2.存入redis, 并限制60秒只能发送一次
        # 3.发送短信

        return http.JsonResponse({'code': RETCODE.OK, 'errmsg': 'OK'})